package com.psu.utils;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Create By : Anusorn
 * Date : 15/11/13
 * Edit By : Anusorn
 * Date : 28/11/13
 */

public class Tools {
	public static String replaceNull(String val) {
		return (val != null)?val:"";
	}
	
	public static String replaceBlankDBTypeString(String val) {
		return (val != null && !val.equals(""))?"'"+val+"'":null;
	}
	
	public static String replaceBlankDBTypeDecimal(String val) {
		return (val != null && !val.equals(""))?val:null;
	}
	
	public void doDespatch(HttpServletRequest req, HttpServletResponse resp, String url) throws ServletException, IOException 
	{
		try 
		{
			RequestDispatcher dispatcher = req.getRequestDispatcher( url );
			dispatcher.forward(req, resp);
		} catch (Exception ex) {
			System.out.println("Error Exception : method doDespatch in Tools.java : " + ex.getMessage());
			ex.printStackTrace();
		}
	}
}
